#!/bin/bash 
echo "--> Starting composer preparing: prepare_composer.sh..." 

SOURCE_ROOT=/vagrant

# May need to download composer dependencies
if [ ! -e $SOURCE_ROOT/webapp/composer.phar ]; then
    echo "Installing composer.phar..."
    echo "----- IMPORTANT: please manually delete composer.phar if we see failure below ----"
    curl -sS https://getcomposer.org/installer | php
	echo "move composer.phar to $SOURCE_ROOT/webapp/"
	mv composer.phar $SOURCE_ROOT/webapp/
	php -c /etc/php-nodebug.ini composer.phar global require "fxp/composer-asset-plugin:1.1.0"
else
    if test `find "${SOURCE_ROOT}/webapp/composer.phar" -mmin +28800`; then
        echo "Composer.phar is older than 20 days, performing self-update"
        php -c /etc/php-nodebug.ini $SOURCE_ROOT/webapp/composer.phar self-update
    else
        echo "Composer.phar is less than 20 days old, update not needed"
    fi
fi


chmod 600 /root/svcconfig/id_rsa/id_rsa

(cd $SOURCE_ROOT/webapp && php -c /etc/php-nodebug.ini composer.phar install && bower --config.interactive=false install cmis-angularjs-directive#develop -p -F --allow-root)
